package com.mbc.rmt.manager;

import com.mbc.common.dao.DBManager;
import com.mbc.common.manager.AbstractMgr;
import com.mbc.common.utils.KeyGenerator;
import com.mbc.rmt.dao.GeneralLedgerDAO;
import com.mbc.rmt.dao.RemittanceDAOFactory;
import com.mbc.rmt.entities.GeneralLedger;

public class GeneralLedgerMgr extends AbstractMgr {
	
	private GeneralLedgerDAO generalLedgerDAO;

	public GeneralLedgerMgr() {
		
	}
	
	public GeneralLedgerMgr(String sessionID) {
		this.sessionId = sessionID;
	}
	
	public void createGL(GeneralLedger l_entity)throws Exception {
		openConnection(DBManager.LINKED_IAIMS);
		try {
			beginTransaction();
			
			generalLedgerDAO = RemittanceDAOFactory.getGeneralLedgerDAO(getConnection());
			generalLedgerDAO.create(l_entity);
			
			commintTransaction();
		} catch(Exception e) {
			rollbackTransaction();
			throw e;
		} finally {
			closeConnection();
		}
		
	}
	
	public void deleteGL(String slipNo)throws Exception {
		openConnection(DBManager.LINKED_IAIMS);
		try {
			generalLedgerDAO = RemittanceDAOFactory.getGeneralLedgerDAO(getConnection());
			generalLedgerDAO.delete(slipNo);
		} catch(Exception e) {
			throw e;
		} finally {
			closeConnection();
		}
	}
	
	public long getGLKey() throws Exception {
		openConnection(DBManager.LINKED_IAIMS);
		try {
			return KeyGenerator.generateKey(getConnection());
		} catch(Exception e) {
			throw e;
		} finally {
			closeConnection();
		}
	}
}
